//
//  Block.m
//  AutoPong
//
//  Created by Pierre DUCHENE on 10/12/09.
//  Copyright 2009 Pierre DUCHENE. All rights reserved.
//

#import "Block.h"


@implementation Block

@synthesize speed;
@synthesize value;

- (id)init
{
    if (self = [super initWithFrame:CGRectMake(150, -20, 20, 20)]) {
		int x = random()%10;
		switch (x) {
			case 0:
			case 1:
			case 2:
			case 3:
				image = [[UIImage imageNamed:@"Block.png"] retain];
				value = 1;
				break;
			case 4:
			case 5:
			case 6:
				image = [[UIImage imageNamed:@"BlockDouble.png"] retain];
				value = 2;
				break;
			case 7:
			case 8:
				image = [[UIImage imageNamed:@"BlockQuadruple.png"] retain];
				value = 4;
				break;
			case 9:
				image = [[UIImage imageNamed:@"BlockTotal.png"] retain];
				value = -1;
				break;
			default:
				image = [[UIImage imageNamed:@"Block.png"] retain];
				value = 1;
				break;
		}
        
    }
    return self;
}

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        int x = random()%10;
		switch (x) {
			case 0:
			case 1:
			case 2:
			case 3:
				image = [[UIImage imageNamed:@"Block.png"] retain];
				value = 1;
				break;
			case 4:
			case 5:
			case 6:
				image = [[UIImage imageNamed:@"BlockDouble.png"] retain];
				value = 2;
				break;
			case 7:
			case 8:
				image = [[UIImage imageNamed:@"BlockQuadruple.png"] retain];
				value = 4;
				break;
			case 9:
				image = [[UIImage imageNamed:@"BlockTotal.png"] retain];
				value = -1;
				break;
			default:
				image = [[UIImage imageNamed:@"Block.png"] retain];
				value = 1;
				break;
		}
    }
    return self;
}


- (void)drawRect:(CGRect)rect {
	[self setBackgroundColor:[UIColor clearColor]];
    [image drawAtPoint:CGPointMake(0, 0)];
}


- (void)dealloc {
    [super dealloc];
}


@end
